package org.shopen.ai.puremvc
{
	import org.puremvc.as3.patterns.facade.Facade;
	import org.puremvc.as3.patterns.observer.Notification;
	import org.puremvc.as3.utilities.statemachine.StateMachine;
	import org.shopen.ai.puremvc.controller.HandleStateChangedCommand;
	import org.shopen.ai.puremvc.controller.algo.HandleEnteringSearchingCommand;
	import org.shopen.ai.puremvc.controller.domain.HandleCitySelectedCommand;
	import org.shopen.ai.puremvc.controller.domain.HandleSelectStateCommand;
	import org.shopen.ai.puremvc.controller.domain.LoadCountryGraphCommand;
	import org.shopen.ai.puremvc.controller.domain.LoadCountryMapXmlCommand;
	import org.shopen.ai.puremvc.controller.popupHandlers.HandleAboutRequestCommand;
	import org.shopen.ai.puremvc.controller.popupHandlers.HandleGeneralErrorCommand;
	import org.shopen.ai.puremvc.controller.project.HandleNavigationRequestCommand;
	import org.shopen.ai.puremvc.controller.project.HandleProjectInitializedCommand;
	import org.shopen.ai.puremvc.controller.project.InitializeProjectCommand;
	import org.shopen.ai.puremvc.controller.project.LoadProjectsCommand;
	import org.shopen.ai.puremvc.controller.project.SelectProjectCommand;
	import org.shopen.ai.puremvc.controller.settings.CommitAutoSettingsCommand;
	import org.shopen.ai.puremvc.controller.settings.CommitManualSettingsCommand;
	import org.shopen.ai.puremvc.controller.settings.InitAutoSettingsCommand;
	import org.shopen.ai.puremvc.controller.settings.InitManualSettingsCommand;
	import org.shopen.ai.puremvc.controller.settings.SelectSettingsCommand;
	import org.shopen.ai.puremvc.controller.startup.StartupCommand;
	import org.shopen.ai.puremvc.model.algo.SearchNode;
	import org.shopen.ai.puremvc.model.algo.SearchProblem;
	import org.shopen.ai.puremvc.model.algo.bfs.BreadthFirstSearchAlgo;
	import org.shopen.ai.puremvc.model.algo.containers.FIFOQueue;
	import org.shopen.ai.puremvc.model.algo.containers.LIFOQueue;
	import org.shopen.ai.puremvc.model.algo.dls.DepthLimitedSearchAlgo;
	import org.shopen.ai.puremvc.model.domain.cities.Distance;
	import org.shopen.ai.puremvc.model.problem.cities.CitiesProblem;
	import org.shopen.ai.puremvc.model.problem.cities.InState;

	public class ApplicationFacade extends Facade
	{
		// <<< FAKE IMPORTS
		var p : CitiesProblem;
		var s : DepthLimitedSearchAlgo;
		var e : SearchNode;
		var f : SearchProblem;
		var i : InState;
		var w : FIFOQueue;
		var ea : LIFOQueue;
		var d : BreadthFirstSearchAlgo;
		var g : Distance;
		// FAKE IMPORTS >>>>
		
		public static const NAME : String = "ApplicationFacade";
		private static const delim : String = ".";
		
		public static const STARTUP : String = NAME + delim + "STARTUP";
		
		/**
         * Singleton ApplicationFacade Factory Method
         */
        public static function getInstance() : ApplicationFacade 
		{
            if ( instance == null ) 
            {
            	instance = new ApplicationFacade( );
            }
            return instance as ApplicationFacade;
        }
        
        protected override function initializeController():void
        {
        	super.initializeController();
        	registerCommand(STARTUP, StartupCommand);
        	registerCommand(ApplicationConstants.REQUEST_PROJECTS_META, LoadProjectsCommand);
        	registerCommand(ApplicationConstants.SELECT_PROJECT, SelectProjectCommand);
        	registerCommand(ApplicationConstants.INITIALIZE_PROJECT, InitializeProjectCommand);
        	registerCommand(ApplicationConstants.PROJECT_INITIALIZED, HandleProjectInitializedCommand);
        	registerCommand(ApplicationConstants.LOAD_COUNTRY_MAPXML, LoadCountryMapXmlCommand);
        	registerCommand(ApplicationConstants.LOAD_COUNTRY_GRAPH, LoadCountryGraphCommand);
        	registerCommand(StateMachine.CHANGED, HandleStateChangedCommand);
        	registerCommand(ApplicationConstants.NAVIGATION_REQUEST, HandleNavigationRequestCommand);
        	registerCommand(ApplicationConstants.ENTERING_PROJECT_SEARCHING, HandleEnteringSearchingCommand);
        	
        	registerCommand(ApplicationConstants.SELECT_STATE, HandleSelectStateCommand);
        	registerCommand(ApplicationConstants.CITY_SELECTED, HandleCitySelectedCommand);
        	
        	registerCommand(ApplicationConstants.INITIALIZE_AUTOMATIC_SETTINGS, InitAutoSettingsCommand);
        	registerCommand(ApplicationConstants.INITIALIZE_MANUAL_SETTINGS, InitManualSettingsCommand);
        	registerCommand(ApplicationConstants.CHANGE_SETTINGS_TYPE, SelectSettingsCommand);
        	registerCommand(ApplicationConstants.COMMIT_MANUAL_SETTINGS, CommitManualSettingsCommand);
        	registerCommand(ApplicationConstants.COMMIT_AUTOMATIC_SETTINGS, CommitAutoSettingsCommand);
        	
        	// popups related commands
        	registerCommand(ApplicationConstants.ABOUT_REQUEST, HandleAboutRequestCommand);
        	registerCommand(ApplicationConstants.GENERAL_ERROR, HandleGeneralErrorCommand);
        }
        
        public function startup(app : Ai) : void
        {
        	sendNotification(STARTUP, app);
        }
        
        override public function sendNotification(notificationName:String, body:Object=null, type:String=null):void
		{
			trace(notificationName + " : " + type);
			notifyObservers(new Notification(notificationName, body, type));
		}
	}
}